<template>
	<view>
		<view style="position: relative;">
			
			<view class="user-background"></view>
			
			<view class="userinfo">
				<view class="avatar-box">
					<image src="../../../static/logo-back.png" class="avatar-background"></image>
					<image :src="userinfo.avatar" mode="" class="avatar"></image>
				</view>

				<view style="display: flex;flex-direction: column;flex: 1;">
					<view style="color: #ffffff;font-size: 34upx;">
						{{userinfo.nickname}}
						<image :src="userinfo.sex==1?'/static/famale.png':'/static/male.png'" class="sex"></image>
					</view>
					<view style="color: #ffffff;font-size: 31upx;">
						{{userinfo.phone?userinfo.phone:'未设置'}}
					</view>
				</view>
				
			</view>
			<image src="/static/setting.png" mode="" style="width: 35upx;height: 35upx;position: absolute;top: 24upx;right: 24upx;z-index: 101;" @click="showProfile"></image>
			<view style="padding: 0 24upx;box-shadow:0upx 4upx 24upx 0upx rgba(43,167,139,0.1);border-radius:24upx;">
				<view class="tab-row">
					<view class="tab tab1" :class="tab==1?'tab-active':''" @click="tab=1">
						<view class="tab-text">我的预约</view>
					</view>
					<view class="tab tab2" :class="tab==2?'tab-active':''" @click="tab=2">
						<view class="tab-text">产品订单</view>
					</view>
				</view>
				<view class="btn-row" v-show="tab==1">
					<view class="btn" @click="showOrderList('service',3)">
						<view class="dot" v-show="booking.using>0">{{booking.using}}</view>
						<image src="../../../static/package.png" class="btn-image" mode=""></image>
						<view class="btn-text">待服务</view>
					</view>
					<view class="btn" @click="showOrderList('service',1)">
						<view class="dot" v-show="booking.finish>0">{{booking.finish}}</view>
						<image src="/static/use.png" class="btn-image" mode=""></image>
						<view class="btn-text">已完成</view>
					</view>
					<view class="btn" @click="showOrderList('service',2)">
						<view class="dot" v-show="booking.comment>0">{{booking.comment}}</view>
						<image src="/static/comment.png" class="btn-image" mode=""></image>
						<view class="btn-text">待评价</view>
					</view>
					<view class="btn" @click="showOrderList('service',0)">
						<view class="dot" v-show="booking.cancel>0">{{booking.cancel}}</view>
						<image src="/static/finish.png" class="btn-image" mode=""></image>
						<view class="btn-text">已取消/退款</view>
					</view>
				</view>
				<view class="btn-row" v-show="tab==2">
					<view class="btn" @click="showOrderList('product',3)">
						<view class="dot" v-show="order.taking>0">{{order.taking}}</view>
						<image src="../../../static/package.png" class="btn-image" mode=""></image>
						<view class="btn-text">待自取</view>
					</view>
					<view class="btn" @click="showOrderList('product',1)">
						<view class="dot" v-show="order.finish>0">{{order.finish}}</view>
						<image src="/static/use.png" class="btn-image" mode=""></image>
						<view class="btn-text">已完成</view>
					</view>
					<view class="btn" @click="showOrderList('product',2)">
						<view class="dot" v-show="order.comment>0">{{order.comment}}</view>
						<image src="/static/comment.png" class="btn-image" mode=""></image>
						<view class="btn-text">待评价</view>
					</view>
					<view class="btn" @click="showOrderList('product',0)">
						<view class="dot" v-show="order.cancel>0">{{order.cancel}}</view>
						<image src="/static/finish.png" class="btn-image" mode=""></image>
						<view class="btn-text">已取消/退款</view>
					</view>
				</view>
				<view class="view-all" v-show="tab==1" @click="showOrderList('service',-1)">
					<text>查看全部预约订单</text>
					<uni-icon type="arrowright" size="20" color="#45AA8C"></uni-icon>
				</view>
				<view class="view-all" v-show="tab==2" @click="showOrderList('product',-1)">
					<text>查看全部产品订单</text>
					<uni-icon type="arrowright" size="20" color="#45AA8C"></uni-icon>
				</view>

			</view>
			<view class="card">
				<view class="title-row">
					<view class="title">我的卡项</view>
					<view class="record" @click="showCardOrder">购买记录</view>
					<uni-icon type="arrowright" size="20" color="#b8b8b8"></uni-icon>
				</view>
				<view class="buy-btn" v-if="cards.length==0">
					暂无卡项
				</view>
				<view class="card-list" v-else>
					<view class="card-item" v-for="(card,index) in cards" :key="index">
						
						<view class="card-expire">
							<view class="card-expire-line"></view>
							剩余{{card.expire_day}}天
						</view>
						<view class="card-head">
							<view class="card-title">
								<view class="card-name">
									{{card.name}}
								</view>
							</view>
							<view class="card-title" style="margin-top: 10upx;">
								<view class="card-service-count">
									￥{{card.price}}
								</view>
								<view class="card-service-count">
									有效期至：{{card.expire_time}}
								</view>
							</view>
						</view>
						<view class="card-service-list">
							<view class="card-service-item">
								<view class="card-service-count">
									以下项目{{card.service_count==0?'次数不限':'任选'+card.service_count+'次'}}，有效期{{card.expire}}个月
								</view>
								<view class="card-count">
									{{card.service_count==0?'次数不限':'剩余'+card.expire_count+'次'}}
								</view>
								
							</view>
							<view class="card-service-item">
								<view class="card-service-name">
									{{card.service_name}}
								</view>
								<view class="card-service-count">
									使用{{card.used_count}}次
								</view>
							</view>
						</view>
						<view class="card-foot">
							<view class="card-foot-item">
								<view class="card-foot-title">
									购买门店：{{card.shop_name}}
								</view>
								<view class="card-foot-btn" @click="showCardPay(card.id)">
									划卡记录
									<uni-icon type="arrowright" size="20" color="#45AA8C"></uni-icon>
								</view>

							</view>
						</view>
					</view>
				</view>

			</view>
		</view>

	</view>
</template>

<script>
	import uniIcon from '../../../components/uni-icon.vue'
	export default {
		components: {
			uniIcon
		},
		data() {
			var isLogin = uni.getStorageSync("token") != null && uni.getStorageSync("token") != "";
			var userinfo = uni.getStorageSync("userinfo");
			return {
				isLogin: isLogin,
				userinfo: userinfo,
				userdata: {},
				order: {},
				booking: {},
				cards: [],
				tab: 1,
			};
		},
		onShow: function() {
			if (this.isLogin) {
				this.getUserData();
			}
		},
		onPullDownRefresh: function() {
			this.getUserData();
		},
		methods: {
			showCardOrder: function() {
				uni.navigateTo({
					url: "/pages/card/list/list",
				})
			},
			showCardPay: function(id) {
				uni.navigateTo({
					url: "/pages/card/pay/pay?id="+id,
				})
			},
			showOrderList: function(type, status) {
				uni.navigateTo({
					url: "/pages/order/list/list?type=" + type + "&status=" + status
				})
			},
			getUserData: function() {
				var that = this;
				that.ajax("/user/info",{
					token: uni.getStorageSync("token"),
				},function(res){
					uni.stopPullDownRefresh();
					that.userinfo = res.data.data.userinfo;
					uni.setStorageSync("userinfo", that.userinfo);
					that.cards = res.data.data.cards;
					console.log(res.data.data.cards);
					console.log(that.cards);
					that.booking = res.data.data.booking;
					that.order = res.data.data.order;
				});
			},
			showProfile:function(){
				uni.navigateTo({
					url:"/pages/user/profile/profile",
				})
			},
		}
	}
</script>

<style>
	.card-item {
		padding: 28upx;
		background: #FFFFFF;
		margin-top: 28upx;
		box-shadow:0upx 2upx 20upx 0upx rgba(43,159,133,0.16);
		border-radius:16upx;
		position: relative;
	}

	.card-title {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding-bottom: 30upx;
		
	}
	.card-head{
		border-bottom: 1upx solid #E7E7E7;
	}
	.card-name {
		color: #4B4B4B;
		font-size: 28upx;
	}

	.card-count {
		font-size: 28upx;
		color: #FF7465;
	}

	.card-service-list {
		padding-bottom: 30upx;
	}

	.card-service-item {
		padding-top: 30upx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.card-service-name {
		color: #8B8B8B;
		font-size: 24upx;
	}
	.card-expire{
		position: absolute;
		top: 32upx;
		right: 16upx;
		padding:6upx 22upx;
		color: #45AA8C;
		font-size: 28upx;
		border:1upx solid #45AA8C;
	}
	.card-expire-line{
		position: absolute;
		left: 50%;
		top: -32upx;
		height: 32upx;
		width: 3upx;
		background: #45AA8C;
	}
	.card-service-count {
		color: #4B4B4B;
		font-size: 24upx;
	}

	.card-foot {
		font-size: 24upx;
		border-top: 1upx solid #E7E7E7;
	}

	.card-foot-item {
		margin-top: 30upx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.card-foot-title {
		color: #8B8B8B;
	}

	.card-foot-btn {
		color: #45AA8C;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.user-background {
		background: #478E7E;
		position: absolute;
		width: 100%;
		height: 400upx;
		top: 0;
		left: 0;
	}

	.userinfo {
		display: flex;
		flex-direction: row;
		padding-top: 20upx;
		align-items: center;
		padding: 20upx;
		position: relative;
		z-index: 100;
	}

	.avatar-box {
		display: flex;
		align-content: flex-end;
		align-items: flex-end;
		margin-right: 43upx;
		position: relative;
		height: 200upx;
		width: 200upx;
	}
	.avatar-background{
		width: 182upx;
		height:176upx;
		position: absolute;
		left: 0;
		top: 0;
	}
	.avatar {
		position: absolute;
		width: 148upx;
		height: 148upx;
		border-radius: 50%;
		left: 18upx;
		top: 18upx;
	}

	.sex {
		width: 30upx;
		height: 30upx;
		margin-left: 8upx;
	}

	.tab-row {
		display: flex;
		flex-direction: row;
		position: relative;
		z-index: 100;
		background: #ffffff;
		border-top-left-radius: 24upx;
		border-top-right-radius: 24upx;
	}
	.tab{
		flex: 1;
		height: 108upx;
		line-height: 108upx;
		background: rgba(40,194,159,0.15);
		font-size: 32upx;
	}
	.tab1 {
		border-top-left-radius: 24upx;
		border-bottom-right-radius: 24upx;
	}
	.tab2 {
		border-top-right-radius: 24upx;
		border-bottom-left-radius: 24upx;
	}
	.tab-text {
		text-align: center;
		color: #8B8B8B;
		font-weight: 600;
	}
	.tab-active{
		background: #FFFFFF;
	}
	.tab1.tab-active {
		box-shadow:none;
		border-bottom-right-radius: 0upx;
	}
	.tab2.tab-active {
		box-shadow:none;
		border-bottom-left-radius: 0upx;
	}
	.tab-active .tab-text {
		color: #45AA8C;
	}

	.btn-row {
		background: #FFFFFF;
		display: flex;
		position: relative;
		z-index: 100;
		flex-direction: row;
		align-content: space-around;
		padding: 40upx 30upx;
		border-bottom: 1upx solid #EFEFEF;
	}

	.btn {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-content: center;
		align-items: center;
		position: relative;
	}

	.dot {
		position: absolute;
		top: 0;
		right: 40upx;
		background: #fb8442;
		height: 34upx;
		line-height: 34upx;
		font-size: 16upx;
		padding: 0 12upx;
		border-radius: 17upx;
		color: #ffffff;
	}

	.btn-image {
		width: 68upx;
		height: 68upx;
	}

	.btn-text {
		font-size: 28upx;
		color: #45AA8C;
		text-align: center;
	}

	.view-all {
		background: #FFFFFF;
		border-bottom-left-radius: 26upx;
		border-bottom-right-radius: 26upx;
		padding: 32upx;
		font-size: 28upx;
		color:#45AA8C;
		line-height: 28upx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.card {
		margin-top: 36upx;
		background: #FFFFFF;
		padding: 30upx 25upx;
	}

	.title-row {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.title {
		flex: 1;
		font-weight: bold;
		font-size: 28upx;
		color: #282828;
	}

	.record {
		color: #b3b3b3;
		font-size: 26upx;
	}

	.buy-btn {
		display: block;
		width: 180upx;
		height: 80upx;
		background: #478E7E;
		color: #ffffff;
		font-size: 25upx;
		line-height: 80upx;
		text-align: center;
		border-radius:80upx;
		margin: 55upx auto 0 auto;
	}
</style>
